﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Model;
using BLL;
using System.IO;
using System.Text;
using System.Data.SqlClient;

public partial class Register : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        UserInfoManager user = new UserInfoManager();
        string name=Txtidno.Text.Trim().ToString ();
        if (Txtidno .Text !=string.Empty )
        {
            if (user.isExists(name))
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('对不起用户名已经被注册');</script>");

            }
            else
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('恭喜用户名还没被注册');</script>");
            }
        }
        else
        {
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('请输入用户名');</script>");
        }
    }
    protected void BtnRegister_Click(object sender, EventArgs e)
    {
        string code = txtCode.Text.Trim().ToUpper();
        string rightCode = Session["Code"].ToString();
        if (code != rightCode)
        {
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('验证码输入错误！');</script>");
            return;
        }
        UserInfo myuser= new UserInfo();
        myuser.Idno = Txtidno.Text.Trim().ToString();
        myuser.Pwd = SecretManager .Encrypt (Txtpwd.Text.Trim().ToString());
        if (Radiogender1.Checked)
        {
            myuser.Gender = "0";
        }
        else if (Radiogender2.Checked)
        {
            myuser.Gender = "1";
        }
        else
        {
            myuser.Gender =" 2";
        }
        myuser.Qq = Txtqq.Text.Trim().ToString();
        myuser.Question = Txtquestion.Text.Trim().ToString();
        myuser.Answer = Txtanswer.Text.Trim().ToString();
        myuser.Email = Txtemail.Text.Trim().ToString();
        myuser.Name = Txtname.Text.Trim().ToString();
        myuser.Remark = Txtremark.Text.Trim().ToString();
        myuser.Lastip = Request.UserHostAddress;
        UserInfoManager manager = new UserInfoManager();
        bool b = manager.Insert(myuser);
        if (b)
        {
            string path = Server.MapPath("~/Upfile") + "\\" + Txtidno.Text.Trim().ToString();
            DirectoryInfo di = new DirectoryInfo(path);
            di.Create();
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('注册成功');</script>");
            
        
        }

        else
        {
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('请检查用户名是否重复');</script>");
        }
    }
}
